<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../day48/demo/js/ajax.js"></script>
</head>
<body>
    
</body>
<script>
    var p1 = readText("1.txt",1000);
    var p2 = readText("2.txt",500);
    var p3 = readText("3.txt",3000);

    Promise.race([p1,p2,p3]).then(list => {
        console.log(list);
    }).catch(err => {
        console.log(err);
    })

    function readText(url, delay = 0){
        var p = new Promise(function(resolve, reject){
            setTimeout(function(){
                $.ajax({
                    type: "get",
                    url:url,
                    success: function(text){
                        resolve(text);
                    }
                })
            },delay)
        })
        return p;
    }
</script>
</html>